﻿using HCore;

namespace MEat
{
    public partial class MEatGame
    {
        private class ClientLobbyState : State<MEatGame>
        {
            public ClientLobbyState(MEatGame owner) : base(owner)
            {
            }

            public override void Enter()
            {
                _owner.Log("Enter ClientLobbyState");

                _owner.networkMgr.Register(PacketType.Start, StartHandle);
                _owner.networkMgr.Register(PacketType.Introduce, IntroduceHandle);
            }

            private void StartHandle(InputMemoryBitStream input)
            {
                _owner._stateMachine.ChangeState<ClientBattleState>();
            }

            private void IntroduceHandle(InputMemoryBitStream input)
            {
                byte playerId = input.ReadByte();
                string name = input.ReadString();
                _owner.commandMgr.serverProxies.Add(playerId, name);
            }

            public override void Execute()
            {
            }

            public override void Exit()
            {
                _owner.networkMgr.Unregister(PacketType.Start);
                _owner.networkMgr.Unregister(PacketType.Introduce);
                _owner.Log("Exit ClientLobbyState");
            }
        }
    }
}